<template>
  <el-form ref="form" :model="form" label-width="100px" :rules="operateType.indexOf('View') > -1 ? {} : rules">
    <el-form-item label="分包单位" prop="subpackageUnitIds">
      <el-select v-model="form.subpackageUnitIds" clearable style="width: 100%;" :disabled="operateType == 'view'">
        <el-option v-for="(item, index) in subpackageUnitIdsOptions" :key="index" :value="item.id"
          :label="item.enterpriseName"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="整改回复" prop="operatorExplain">
      <el-input type="textarea" :rows="4" v-model="form.operatorExplain" :disabled="operateType == 'view'"></el-input>
    </el-form-item>
    <el-form-item label="现场照片" prop="operatorPhoto">
      <ImageUpload ref="imageUpload" @addNumData="addNumData" @delNumData="delNumData" v-model="form.operatorPhoto" v-if="operateType != 'view'"></ImageUpload>
      <el-row v-else>
        <el-col :span="6" v-for="url in form.pics" :key="url">
          <el-image style="width: 150px; height: 150px" :src="url" :preview-src-list="form.pics"></el-image>
        </el-col>
      </el-row>
    </el-form-item>
    <el-form-item label="合作方罚款" prop="isFine" v-if="form.subpackageUnitIds">
      <el-radio v-model="form.isFine" label="0" :disabled="operateType == 'view'">不罚款</el-radio>
      <el-radio v-model="form.isFine" label="1" :disabled="operateType == 'view'">罚款</el-radio>
    </el-form-item>
    <div v-if="form.isFine == '1' && form.subpackageUnitIds">
      <el-form-item label="罚款金额" prop="fineMoney">
        <el-input-number style="width: 100%;" v-model="form.fineMoney" :min="0" :disabled="operateType == 'view'"
          :max="999999999999999999"></el-input-number>
      </el-form-item>
      <el-form-item label="罚款说明" prop="fineExplain">
        <el-input type="textarea" :rows="4" v-model="form.fineExplain" :disabled="operateType == 'view'"></el-input>
      </el-form-item>
    </div>
    <el-form-item label="项目扣分" prop="isFine" v-if="!form.subpackageUnitIds">
      <el-radio v-model="form.isFine" label="0" :disabled="operateType == 'view'">不扣分</el-radio>
      <el-radio v-model="form.isFine" label="1" :disabled="operateType == 'view'">扣分</el-radio>
    </el-form-item>
    <div v-if="form.isFine == '1' && !form.subpackageUnitIds">
      <el-form-item label="扣分分数" prop="fineMoney">
        <el-input-number style="width: 100%;" v-model="form.fineMoney" :min="0" :disabled="operateType == 'view'"
          :max="999999999999999999"></el-input-number>
      </el-form-item>
      <el-form-item label="扣分说明" prop="fineExplain">
        <el-input :disabled="operateType == 'view'" type="textarea" :rows="4" v-model="form.fineExplain"></el-input>
      </el-form-item>
    </div>
  </el-form>
</template>
<script>
function required() {
  return { required: true, message: "此项不能为空", trigger: "change" }
}
export default {
  name: "ReviseForm",
  props: {
    form: {
      type: Object,
      default: () => { }
    },
    operateType: {
      type: String,
      default: "add"
    },
    subpackageUnitIdsOptions: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      uploadList:[],
      rules: {
        // subpackageUnitIds: [required()],
      },
    }
  },
  methods: {
    validate() {
      return new Promise(resolve => {
        this.$refs.form.validate(async valid => {
          if (valid) {
            resolve(true)
          } else {
            resolve(false)
          }
        })
      })
    },
    addNumData(data){
      this.uploadList.push(data.fileId);
    },
    delNumData(data){
      this.uploadList.splice(data, 1)
    },
    pic(){
      return this.uploadList.toString()
    }
  },
}
</script>
<style lang="scss" scoped></style>